package com.lzx.applib.gson;

import android.text.TextUtils;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.lzx.applib.utils.LogUtil;

import java.lang.reflect.Type;

/**
 * Created by Administrator on 16/11/20.
 */

public class BooleanTypeAdapter implements JsonDeserializer<Boolean> {

    private static final String TAG = "BooleanTypeAdapter";

    @Override
    public Boolean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        if (json != null) {
            boolean data = json.getAsBoolean();
            if (!data) {
                try {
                    int value = json.getAsInt();
                    return value  != 0;
                } catch (Exception e) {
                    return false;
                }
            }
            return data;
        }
        return false;
    }
}
